import java.util.Random;
class Calculator {


// ****************************** Date : 1/8/13 ****************************** 

	boolean bln;
	byte b;
	short s;
	int i;
	long l;
	float f;
	double d;
	char c;
	String str;
	

// ****************************** Date : 31/7/13 ****************************** 


	// Method for generating Random Numbers
	public static int[][] generateRandomIntMatrix(int row, int col) {
		int[][] matrix = new int[row][col];
		for(int i=0; i<matrix.length; i++) {
			for(int j=0; j<matrix[0].length;j++) {
				matrix[i][j] = (int)(Math.random()*100);
			}
		}
		return matrix;
	}

	//Printing multidimensional integer array

	public static void printIntMultiDimensionalArray(int[][] array){
		for(int i=0;i<array.length;i++){
			for(int j=0; j<array[i].length;j++){	
				System.out.print(array[i][j] + " ");
			}
			System.out.println();
		}
	}

	// Sum of all the elements in Multidimensional Array

	public static int sumOfAllElements(int[][] matrix) {	
		int temp=0;
		for(int i=0;i<matrix.length;i++){
			for(int j=0;j<matrix.length;j++){
				temp+=matrix[i][j];
			}
		}
		return temp;
	}

	// Sum of Row the elements in Multidimensional Array
	public static int sumOfRowElements(int[][] matrix) {
		int rowTotal=0;
		for(int i=0;i<matrix.length;i++){
			for(int j=0;j<matrix.length;j++){
				rowTotal+=matrix[i][j];
			}
			System.out.println(rowTotal);
			rowTotal=0;
		}
		return rowTotal;
	}
		

	// Method to Add two  matrix
	public static void addTwoMatrix(int[][] matrix1, int[][] matrix2){
		for(int i=0;i<matrix2.length;i++){
			for(int j=0;j<matrix2.length;j++){
				System.out.print(matrix1[i][j]+matrix2[i][j]+" ");
			}
			System.out.println();
		}
	}
	
	
	// Method to multiply two  matrix
	public static int[][] multiplyTwoMatrix(int[][] matrix1, int[][] matrix2){
		int[][] result=new int [matrix1[1].length][matrix2.length];
		for(int i=0;i<matrix1[1].length;i++){
			for(int j=0;j<matrix2.length;j++){
				for(int k=0;k<matrix1.length;k++){
					result[i][j]+=(matrix1[i][k]*matrix2[k][j]);
				//System.out.print(result[i][j]+" ");
				}
			}
			System.out.println();
		}
		return result;
	}


// *********************************** Date : 30/7/13 ***********************************


	//Method for reversing String
	public static String Reverse(String str){
		char charArray[] = str.toCharArray();
		for (int i = 0; i <str.length(); i++){
			if(charArray[i] == ' ')
			return Reverse(str.substring(i + 1)) + str.substring(0, i) + " ";
		}
		return str + " ";
	}

	// Method for reversing the String 
	/*
	public static String reverseString(String str){
		char[] chs = str.toCharArray();
		int i=0, j=chs.length-1;
		while (i < j) {
        	// swap chs[i] and chs[j]
			char t = chs[i];
			chs[i] = chs[j];
			chs[j] = t;
			i++; j--;
		}
		return chs.toString();

		String reverseString;
		char charArray[] = str.toCharArray();
		char charArrayReverse[] = new char[str.length()];
		for(int i=0; i<str.length();i++){
			for(int j=str.length();j>0;j--){
				charArrayReverse = charArray.charAt(j);
			}
		}	
		reverseString=charArrayReverse.toString();
		return reverseString;
	}
*/

	// Method for Fibonacci series
	public static void fibonacci(int num){
		if(num == 1 || num == 2){
			System.out.println("1");
        }
        int fibo1=0, fibo2=1, fibonacci=1;
        for(int i= 2; i<= num; i++){
            fibonacci = fibo1 + fibo2; 
            fibo1 = fibo2;
            fibo2 = fibonacci;
			System.out.println(fibo1);
        }    
	}

	// Method for even numbers
	public static void isEven(int start, int end){
		for(int i=start;i<end;i++){
			if(i%2==0)
			System.out.print(i + " ");
		}
	}

	// Method for odd numbers
	public static void isOdd(int start, int end){
		System.out.println();
		for(int i=start;i<end;i++){
			if(i%2!=0)
			System.out.print(i + " ");
		}
	}
/*
	// Method for prime numbers
	public static void isPrime(int num){
		System.out.println();
		for(int i=2;i<num;i++){
			for(int j=2;j<i;j++){
				if(i%j!=0)
				System.out.print(i + " ");
			}
		}
	}
*/

	public static boolean isPrime2(int number){
        for(int i=2; i<number; i++){
			if(number%i == 0){
               return false;
			}
        }
        return true; 
    }
	
	// Method for generating Random Numbers
	public static int[] generateRandomIntArray(int size) {
		int[] array = new int[size];
		for(int i=0; i<array.length; i++) {
			array[i] = (int)(Math.random()*100);	
		}
		return array;
	}

	//Printing integer array
	public static void printIntArray(int[] array){
		System.out.println();
		for(int i=0;i<array.length;i++){	
			System.out.print(array[i] + " ");
		}
	}

	// Sum of all the elements in Array
	public static int sumOfAllElementsInArray(int[] array) {	
		int temp=0;
		for(int i=0;i<array.length;i++){		
			temp+=array[i];
		}
		return temp;
		//System.out.println(temp);
	}

	// Method for generating Random Numbers
	public static double[] generateRandomDoubleArray(int size) {
		double[] array = new double[size];
		for(int i=0; i<array.length; i++) {
			array[i] = Math.random();	
		}
		return array;
	}

	//Printing double array
	public static void printDoubleArray(double[] array){
		System.out.println();
		for(int i=0;i<array.length;i++){	
			System.out.print(array[i] + " ");
		}
	}

	// Method for generating Random Characters
	public static char[] generateRandomCharArray(int size) {
		char[] array = new char[size];
		final String alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		final int N = alphabet.length();
		Random r = new Random();
		for(int i=0; i<array.length; i++) {
			array[i] = alphabet.charAt(r.nextInt(N));	
		}
		return array;  
	}
	
	//Printing char array
	public static void printCharArray(char[] array){
		System.out.println();
		for(int i=0;i<array.length;i++){	
			System.out.print(array[i] + " ");
		}
	}

	// Maximum number in Array
	public static int maxNoInArray(int[] array) {	
		int temp=0;
		for(int i=0;i<array.length;i++){		
			if(temp<array[i])
			temp = array[i];
		}
		return temp;
	}

	// Reverse an int Array
	public static int[] reverseIntArray(int[] array) {
		for(int i=0;i<array.length/2; i++){
			int temp = array[i];
			array[i] = array[array.length-1 - i];
			array[array.length-1 - i] = temp;	
		}
		return array;
	}
	
	//Count vowels from char array
	public static int countVowels(char[] array){
		int count=0;
		System.out.println();
		for(int i=0;i<array.length;i++){	
			if(array[i]=='a' || array[i]=='e' || array[i]=='i' || array[i]=='o' || array[i]=='u' || array[i]=='A' || array[i]=='E' || array[i]=='I' || array[i]=='O' || array[i]=='U' ){
				count++;
			}
		}
		return count;
	}



// ***************************** Date : 29/7/13 ***************************** 


	//Method for leap year..
	public static boolean LeapYear(int year){
        System.out.println("\nThis program calculates leap year.");
        boolean isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
        if (isLeapYear)
            System.out.println(year + " is a leap year.");
         else
            System.out.println(year + " is not a leap year.");
		return isLeapYear;	
    }
	
	
	// Method for even and odd logic..
	public static boolean EvenOdd(int num){
		System.out.println("\nThis program calculates Even or Odd number.");
		if(num%2==0){
			System.out.println( num + " is an even number");
			return true;
		}
		else{
			System.out.println( num + " is an odd number");
			return false;
		}
	}

	//Method to find prime number
	public static boolean isPrime(int number){
        System.out.println("\nThis program calculates wheather number is prime or not.");
		for(int i=2; i<number; i++){
			if(number%i == 0){
				System.out.println(number + " is not a prime number");
				return false;
			}
			else{
				System.out.println(number + " is a prime number");
				return true;
			}
        }
        return true;
    }

	// Method for printing a statement using while loop
	public static void rept(int a){
		System.out.println("\nThis program print statements for " +a+ " times.");
		int i=0;
		while(i<a){
			System.out.println("I will practice everyday");
			i++;
		}
	}

	// Method for printing Even Numbers
	public static void Even(int num){
		System.out.println("\nThis program prints Even number between 0 to " +num);
		for(int i=0;i<num;i++){
			if(i%2==0)
			System.out.println(i);
		}
	}

	// Method for printing Odd Numbers
	public static void isOdd(int num){
		System.out.println("\nThis program prints odd number between 0 to " +num);
		for(int i=0;i<num;i++){
			if(i%2!=0)
			System.out.println(i);
		}
	}

	// Method for Maximum Number
	public static void isMax(int num1, int num2){
		if(num1>num2)
			System.out.println(num1+ " is greater than " +num2);
		else
			System.out.println(num2+ " is greater than " +num1);
	}

	//Largest prime number
	public static boolean isLargestPrime(long number){
        System.out.println("\nThis program calculates whether number is prime or not.");
		for(int i=2; i<number; i++){
			if(number%i == 0){
				System.out.println(number + " is not a prime number");
				return false;
			}
			else{
				System.out.println(number + " is a prime number");
				return true;
			}
        }
        return true;
    }
}